home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / shell / igo / gosource / cell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  3.1 KB  |  169 lines

  1. #define DEBUG 0
  2. /* 
  3.     TOWNS囲碁棋譜記録プログラム
  4.                                           1992/07/22  久保田俊也
  5.  
  6.     92/07/22        kifuデ-タのセルを操作する関数の集まり 
  7.                 現在のバ-ジョンはMAX_TE_NUMBER以上のデ-タを要求すると
  8.                 NULLを返す
  9.                 
  10.  
  11. */
  12. #include <stdlib.h>
  13. #include "igo.h"
  14. #include "banx.h"
  15. #include "kiffile.h"
  16.  
  17. /*
  18. static TE *cell= NULL;
  19.  */
  20. static TE cell[MAX_TE_NUMBER];
  21. static TE *free_p;
  22. static int te_arg_no=0;
  23.  
  24. cell_init()
  25. {
  26. int i;
  27. /*
  28. int physicalMax;
  29. int    logicalMax;
  30. int    maxMemory;
  31.  
  32.     if(cell==NULL){
  33.         physicalMax = TL_checkMemory(0);
  34.         logicalMax = TL_checkMemory(2);
  35.         maxMemory = (( physicalMax <logicalMax ) ? physicalMax : logicalMax );
  36.         if((cell=my_alloc(maxMemory-200*1024)==NULL){
  37.             return -1;
  38.         }
  39.         max_te_number=(maxMemory-200*1024)/sizeof(TE);
  40.     }
  41.  
  42.  */
  43.     for(i=0;i<MAX_TE_NUMBER-1;i++){
  44.         cell[i].next = &cell[i+1];
  45.         cell[i].iro  = FREE_CELL; /* free_cell の意味で使っている */
  46.     }
  47.     cell[MAX_TE_NUMBER-1].next = NULL;
  48.     cell[MAX_TE_NUMBER-1].iro  = FREE_CELL; /* free_cell の意味で使っている */
  49.  
  50.     free_p = &cell[0];
  51.     return 0;
  52.     
  53. }
  54.  
  55. TE *cell_get()
  56. {
  57. TE *wk_te;
  58.  
  59.     if(free_p == NULL){
  60.         return NULL;
  61.     }else{
  62.         wk_te = free_p;
  63.         free_p = free_p->next;
  64.         return wk_te;
  65.     }
  66.  
  67. }
  68.  
  69. cell_free(TE *p)
  70. {
  71.  
  72.     p->next = free_p;
  73.     p->iro  = FREE_CELL;
  74.     free_p = p;
  75.     return 0;
  76. }
  77.  
  78. TE_ARG cell_read()
  79. {
  80. TE_ARG te_arg;
  81.  
  82.     while(cell[te_arg_no].iro  == FREE_CELL){
  83.         if( te_arg_no > MAX_TE_NUMBER-1){
  84.             te_arg_no = 0;
  85.             te_arg.no = -1;
  86.             return (te_arg);
  87.         }
  88.         te_arg_no++;
  89.     }
  90.  
  91.     if( te_arg_no > MAX_TE_NUMBER-1){
  92.         te_arg_no = 0;
  93.         te_arg.no = -1;
  94.         return (te_arg);
  95.     }
  96.  
  97.     te_arg.no      = te_arg_no;
  98.     if(cell[te_arg_no].prev == NULL){
  99.         te_arg.prev = -1;
  100.     }else{
  101.         te_arg.prev    = cell[te_arg_no].prev - &cell[0];
  102.     }
  103.     if(cell[te_arg_no].next == NULL){
  104.         te_arg.next = -1;
  105.     }else{
  106.         te_arg.next    = cell[te_arg_no].next - &cell[0];
  107.     }
  108.     if(cell[te_arg_no].brother == NULL){
  109.         te_arg.brother = -1;
  110.     }else{
  111.         te_arg.brother    = cell[te_arg_no].brother - &cell[0];
  112.     }
  113.     te_arg.iro     = cell[te_arg_no].iro;
  114.     te_arg.ichi    = cell[te_arg_no].ichi;
  115.     te_arg.comment = cell[te_arg_no].comment;
  116.     te_arg_no++;
  117.  
  118.     return (te_arg);
  119. }
  120.  
  121. int cell_write(TE_ARG te_arg)
  122. {
  123. static int i;
  124.  
  125.     if (te_arg.no > MAX_TE_NUMBER-1){
  126.         return (-1);
  127.     }
  128.  
  129.     i               = te_arg.no;
  130.     if(te_arg.prev == -1){
  131.         cell[i].prev    = NULL;
  132.     }else{
  133.         cell[i].prev    = te_arg.prev + &cell[0];
  134.     }
  135.     if(te_arg.next == -1){
  136.         cell[i].next    = NULL;
  137.     }else{
  138.         cell[i].next    = te_arg.next + &cell[0];
  139.     }
  140.     if(te_arg.brother == -1){
  141.         cell[i].brother   = NULL;
  142.     }else{
  143.         cell[i].brother   = te_arg.brother + &cell[0];
  144.     }
  145.     cell[i].iro     = te_arg.iro;
  146.     cell[i].ichi    = te_arg.ichi;
  147.     cell[i].comment = te_arg.comment;
  148.  
  149.     return (0);
  150. }
  151.  
  152. int cell_write_finish()
  153. {
  154. int i;
  155. TE *wk_p;
  156.  
  157.     wk_p = NULL;
  158.     for(i=0;i<MAX_TE_NUMBER;i++){
  159.         if(cell[MAX_TE_NUMBER-i-1].iro == FREE_CELL){
  160.             cell[MAX_TE_NUMBER-i-1].next = wk_p;
  161.             wk_p         = &cell[MAX_TE_NUMBER-i-1];
  162.         }
  163.     }
  164.  
  165.     free_p = wk_p;
  166.  
  167.     return (0);
  168. }
  169.